// 定义表示记分牌的类
export default class ScorePanel {
    // score & level 用来记录分数和等级
    private score: number = 1;
    public level: number = 1;

    // 分数和等级的dom元素
    private scoreElement: HTMLElement;
    private levelElement: HTMLElement;
    private showScoreEle: HTMLElement;
    private showDeadEle: HTMLElement;

    // 设置最高的等级
    // 设置升级的临界值
    // 初始化dom元素
    constructor(private maxLevel: number = 10, private upScore: number = 10) {
        // 注意加！表示不可能为空
        this.scoreElement = document.getElementById('score')!;
        this.levelElement = document.getElementById('level')!;
        this.showScoreEle = document.getElementById('finally-score')!;
        this.showDeadEle = document.getElementById('end')!;
        this.init();
    }

    init(){
        this.score = 1;
        this.level = 1;
        this.scoreElement.innerText = this.score + '';
        this.levelElement.innerText = this.level + '';
    }

    showDeadMsg(msg:string){
        this.showDeadEle.style.display = msg;
        this.showScoreEle.innerText=this.score+'';
    }

    // 设置一个加分的方法
    addScore(): void {
        this.scoreElement.innerText = ++this.score + '';
        if (this.score % this.upScore === 0) {
            this.upLevel();
        }
    }

    // 设置一个提升等级的方法
    upLevel(): void {
        if (this.level >= this.maxLevel) return;
        this.levelElement.innerText = ++this.level + '';
    }

    // 重置等级与分数
    reset(){
        this.init();
    }
}